# -*- coding: utf-8 -*-
# Author: tom
# time: 2024/2/29 17:29
# description：
import re
# from asyncio import run

import pytest
from playwright.sync_api import Page, expect, sync_playwright,Playwright


# 下面是pytest代码
# def test_login_playwrigh(page:Page):
#     page.goto('https://xbasetest.dxbim.com:8333/user/login')
#     page.fill('//*[@id="login_userName"]', '18516700020')
#     page.fill('//*[@id="login_password"]', 'qhdia111')
#     page.click('//button[@type="submit"]')
#     expect(page).to_have_title(re.compile('首页'))
#     expect(page).to_have_url(re.compile('.*dxbim.com:8333'))

# if __name__ == '__main__':
#     pytest.main(["-vs","login_testcase.py"])

# 下面是python代码
def test_login_playwrigh(playwright:Playwright)->None:
    browser=playwright.chromium.launch(headless=False)#可以看到浏览器，默认看不到浏览器
    context=browser.new_context()
    page=context.new_page()
    page.goto('https://xbasetest.dxbim.com:8333/user/login')
    page.fill('//*[@id="login_userName"]', '18516700020')
    page.fill('//*[@id="login_password"]', 'qhdia111')
    page.click('//button[@type="submit"]')
    expect(page).to_have_title(re.compile('首页'))
    expect(page).to_have_url(re.compile('.*dxbim.com:8333'))
    browser.close()
    context.close()

with sync_playwright() as playwright:
    test_login_playwrigh(playwright)

